import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		// 微信登陆Code码
		weixincode: null,
		service_id: null,
		userinfo: null,
		longitudeAndLatitude: null,
		// 门诊的id
		id: null,
		// 用户类型：2为诊所
		identity: null,
		// 存储opengid
		openid: null,

		// 即时通讯
		imsig: null,

		// --------------------------------聊天用的----------------------------------------
		// isLogin: false,
		// isSDKReady: false, // TIM SDK 是否 ready

		// conversationActive: {}, //聊天进行中的会话
		// toUserId: '', //聊天对象id
		// conversationList: [], //会话列表
		// currentMessageList: [], //消息列表
		// ================================聊天用的========================================

	},
	mutations: {
		storeWeixincode(state, options) {
			state.weixincode = options;
			console.log(`存储code成功了...`)
		},
		// 存储个人信息
		storePersonalInformation(state, options) {
			state.userinfo = options;
			console.log(`存储个人信息成功了...`);
		},
		// 存储经纬度
		storeLongitudeAndLatitude(state, options) {
			state.longitudeAndLatitude = options;
			console.log(`经纬度保存成功了...`);
		},
		storeClinicId(state, id) {
			state.id = id;
			console.log(`门诊的id存储成功了`);
		},
		stroeIdentity(state, identity) {
			state.identity = identity;
			console.log(`用户类型存储成功了...`);
		},
		storeOpenid(state, openids) {
			state.openid = openids;
			console.log(`openid存储成功了`);
		},
		// ===================
		// 存储医生端id
		storeService_id(state, id) {
			state.service_id = id;
			console.log(`service_id存储成功了`);
		},
		// 即时通讯的usersig用于登录
		storeImsig(state, options) {
			state.imsig = options;
			console.log(state.imsig);
			console.log(`即时通讯的usersig用于登录存储成功...`);
		}
		// -------------------
		// ===============================聊天的功能=============================
		//更新登录状态
		// toggleIsLogin(state, isLogin) {
		//   state.isLogin = typeof isLogin === 'undefined' ? !state.isLogin : isLogin
		// },
		// //更新TIMSDK状态
		// toggleIsSDKReady(state, isSDKReady) {
		//   state.isSDKReady = typeof isSDKReady === 'undefined' ? !state.isSDKReady : isSDKReady
		// },
		// //退出登录重置状态
		// reset(state) {
		//   state.isLogin = false
		//   state.isSDKReady = false
		// },
		// //选择好友聊天--创建会话/拼接会话id
		// createConversationActive(state, toUserId) {
		//   state.conversationActive.conversationID = 'C2C' + toUserId
		//   state.toUserId = toUserId
		//   state.currentMessageList = []
		// },
		// //选择已有会话聊天--更新选中会话详情
		// updateConversationActive(state, conversationItem) {
		//   state.conversationActive = Object.assign({}, conversationItem.conversation);
		//   state.toUserId = conversationItem.user.userId
		//   state.currentMessageList = []
		// },
		// //更新会话列表
		// updateConversationList(state, newConversationList) {
		//   state.conversationList = newConversationList
		// },
		// /**
		//  * 将消息插入当前会话列表
		//  * 调用时机：收/发消息事件触发时
		//  * @param {Object} state
		//  * @param {Message[]|Message} data
		//  * @returns
		//  */
		// pushCurrentMessageList(state, data) {
		//   // 还没当前会话，则跳过
		//   if (Array.isArray(data)) {
		//     // 筛选出当前会话的消息
		//     const result = data.filter(item => item.conversationID === state.conversationActive.conversationID)
		//     state.currentMessageList = [...state.currentMessageList, ...result]
		//   } else if (data.conversationID === state.conversationActive.conversationID) {
		//     state.currentMessageList = [...state.currentMessageList, data]
		//   }
		//   console.log('1111')
		//   console.log(state.currentMessageList)
		// },
		// /**
		//  * 滑到顶部请求更多的历史消息
		//  * */
		// unshiftCurrentMessageList(state, data) {
		//   console.log(data)
		//   if (data) {
		//     state.currentMessageList = [...data, ...state.currentMessageList]
		//   }
		// },
		// // -------------------------------聊天的功能-----------------------------
	},
	actions: {}
})
export default store
